﻿@using Microsoft.AspNetCore.Identity;
@using MyApp.Components.Pages.Account.Manage
@using MyApp.Data;

@inject NavigationManager NavigationManager
@inject SignInManager<ApplicationUser> SignInManager

<ul class="mt-4">
    <li>
        <NavLink class="@ManageNavPages.IndexNavClass(NavigationManager)" 
                 id="profile" href="@ManageNavPages.Index" Match="NavLinkMatch.All">Profile</NavLink>
    </li>
    <li>
        <NavLink class="@ManageNavPages.EmailNavClass(NavigationManager)" 
                 id="manage-email" href="@ManageNavPages.Email">Email</NavLink>
    </li>
    <li>
        <NavLink class="@ManageNavPages.ChangePasswordNavClass(NavigationManager)" 
                 id="change-password" href="@ManageNavPages.ChangePassword">Password</NavLink>
    </li>
    @if (hasExternalLogins)
    {
        <li id="external-logins">
            <NavLink class="@ManageNavPages.ExternalLoginsNavClass(NavigationManager)" 
                     id="external-login" href="@ManageNavPages.ExternalLogins">External logins</NavLink>
        </li>
    }
    <li>
        <NavLink class="@ManageNavPages.TwoFactorAuthenticationNavClass(NavigationManager)" 
                 id="two-factor" href="@ManageNavPages.TwoFactorAuthentication">Two-factor authentication</NavLink>
    </li>
    <li>
        <NavLink class="@ManageNavPages.PersonalDataNavClass(NavigationManager)" 
                 id="personal-data" href="@ManageNavPages.PersonalData">Personal data</NavLink>
    </li>
    @if (HostContext.AppHost.HasPlugin<ApiKeysFeature>())
    {
        <li>
            <NavLink class="@ManageNavPages.PageNavClass(NavigationManager, "Account/Manage/ApiKeys")" 
                     id="api-keys" href="Account/Manage/ApiKeys">API Keys</NavLink>
        </li>
    }
</ul>

@code {
    private bool hasExternalLogins;

    protected override async Task OnInitializedAsync()
    {
        hasExternalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).Any();
    }
}
